package com.fzfnn.scrapbook.controller;

import com.fzfnn.scrapbook.service.JournalLikeService;
import com.fzfnn.scrapbook.util.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/journal/like")
@Tag(name = "点赞接口", description = "其他用户手账点赞相关接口")
public class JournalLikeController {

    @Autowired
    private JournalLikeService journalLikeService;

    @PostMapping("/{journalId}")
    @Operation(summary = "点赞")
    public R like(@PathVariable int journalId,@RequestHeader("Authorization") String token) {
        return journalLikeService.likeJournal(journalId, token);
    }

    @DeleteMapping("/{journalId}")
    @Operation(summary = "取消点赞")
    public R unlike(@PathVariable int journalId, @RequestHeader("Authorization") String token) {
        return journalLikeService.unlikeJournal(journalId, token);
    }

    @GetMapping("/count/{journalId}")
    @Operation(summary = "获取点赞数")
    public R getLikeCount(@PathVariable int journalId) {
        return journalLikeService.getLikeCount(journalId);
    }

    @GetMapping("/liked")
    @Operation(summary = "判断是否点赞")
    public R isLiked(@RequestParam int journalId, @RequestHeader("Authorization") String token) {
        return journalLikeService.isLiked(journalId, token);
    }
    @GetMapping("/getLikeUser")
    @Operation(summary = "获取点赞用户")
    public R getLikeUser(@RequestHeader("Authorization") String token,@RequestParam int journalId) {
        return journalLikeService.getLikedUsers(token,journalId);
    }
    @GetMapping("/getLikeJournal")
    @Operation(summary = "获取点赞手账")
    public R getLikeJournal(@RequestHeader("Authorization") String token) {
        return journalLikeService.getLikedJournals(token);
    }
}
